﻿using System;
using System.Windows;
using System.Windows.Input;

namespace Mari.SmartHotel.Controls
{
    /// <summary>
    /// Interaction logic for MessageBox186Window.xaml
    /// </summary>
    public partial class SHMessageBoxWindow : Window
    {
        //public string IdTelegram
        //{
        //    get { return (string)GetValue(IdTelegramProperty); }
        //    set { SetValue(IdTelegramProperty, value); }
        //}

        //// Using a DependencyProperty as the backing store for Message.  This enables animation, styling, binding, etc...
        //public static readonly DependencyProperty IdTelegramProperty =
        //    DependencyProperty.Register("IdTelegram", typeof(string), typeof(SHMessageBoxWindow));

        public string Message
        {
            get { return (string)GetValue(MessageProperty); }
            set { SetValue(MessageProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Message.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty MessageProperty =
            DependencyProperty.Register("Message", typeof(string), typeof(SHMessageBoxWindow));

        public string Caption
        {
            get { return (string)GetValue(CaptionProperty); }
            set { SetValue(CaptionProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Caption.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty CaptionProperty =
            DependencyProperty.Register("Caption", typeof(string), typeof(SHMessageBoxWindow));

        public MessageBoxButton MessageBox186Button { get; set; }

        public MessageBoxImage MessageBox186Image { get; set; }

        public MessageBoxResult MessageBox186Result { get; set; }

        public Exception Exception { get; set; }

        public bool IsDialog;

        public SHMessageBoxWindow()
        {
            InitializeComponent();
        }

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            MessageBox186Result = MessageBoxResult.OK;

            this.Close();
        }

        private void btnYes_Click(object sender, RoutedEventArgs e)
        {
            MessageBox186Result = MessageBoxResult.Yes;

            this.Close();
        }

        private void btnNo_Click(object sender, RoutedEventArgs e)
        {
            MessageBox186Result = MessageBoxResult.No;
            this.Close();
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            MessageBox186Result = MessageBoxResult.Cancel;
            this.Close();
        }

        private void MessageBoxWindow_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            //if (Configuration.SmartClient186.Instance.AdvancedUIMode)
            //{
            //    this.Opacity = 0.7;
            //}
            DragMove();
        }

        private void MessageBoxWindow_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            this.Opacity = 1;
        }

        private void MessageBoxWindow_Loaded(object sender, RoutedEventArgs e)
        {

            if (!this.IsDialog)
            {
                Application.Current.MainWindow.Closing += new System.ComponentModel.CancelEventHandler(MainWindow_Closing);
                Application.Current.MainWindow.IsHitTestVisible = false;
            }

            txtMessage.Width = this.Width - 50;
            if (Exception != null)
            {
                spExpander.Visibility = Visibility.Visible;
                txtExceptionMessage.Text = this.Exception.ToString();
            }

            //if (!string.IsNullOrEmpty(IdTelegram))
            //{
            //    txtIDTelegram.Visibility = Visibility.Visible;
            //    btnCopyIdTelegram.Visibility = Visibility.Visible;
            //}
            //else
            //{
            //    txtIDTelegram.Visibility = Visibility.Collapsed;
            //    btnCopyIdTelegram.Visibility = Visibility.Collapsed;
            //}

            switch (MessageBox186Button)
            {
                case MessageBoxButton.OK:
                    btnOk.Visibility = Visibility.Visible;
                    btnYes.Visibility = Visibility.Collapsed;
                    btnCancel.Visibility = Visibility.Collapsed;
                    btnNo.Visibility = Visibility.Collapsed;
                    btnOk.Focus();
                    break;
                case MessageBoxButton.OKCancel:
                    btnOk.Visibility = Visibility.Visible;
                    btnYes.Visibility = Visibility.Collapsed;
                    btnCancel.Visibility = Visibility.Visible;
                    btnNo.Visibility = Visibility.Collapsed;
                    btnOk.Focus();
                    break;
                case MessageBoxButton.YesNo:
                    btnOk.Visibility = Visibility.Collapsed;
                    btnYes.Visibility = Visibility.Visible;
                    btnCancel.Visibility = Visibility.Collapsed;
                    btnNo.Visibility = Visibility.Visible;
                    btnYes.Focus();
                    break;
                case MessageBoxButton.YesNoCancel:
                    btnOk.Visibility = Visibility.Collapsed;
                    btnYes.Visibility = Visibility.Visible;
                    btnCancel.Visibility = Visibility.Visible;
                    btnNo.Visibility = Visibility.Visible;
                    btnYes.Focus();
                    break;
                default:
                    break;
            }

            if (!this.IsDialog)
            {
                imgError.Visibility = Visibility.Collapsed;
                imgInfo.Visibility = Visibility.Collapsed;
                imgWarning.Visibility = Visibility.Collapsed;
                imgQuestion.Visibility = Visibility.Collapsed;
                imgAsterisk.Visibility = Visibility.Visible;
                return;
            }

            switch (MessageBox186Image)
            {
                case MessageBoxImage.Error:
                    imgError.Visibility = Visibility.Visible;
                    imgInfo.Visibility = Visibility.Collapsed;
                    imgWarning.Visibility = Visibility.Collapsed;
                    imgQuestion.Visibility = Visibility.Collapsed;
                    imgAsterisk.Visibility = Visibility.Collapsed;
                    break;
                case MessageBoxImage.Warning:
                    imgError.Visibility = Visibility.Collapsed;
                    imgInfo.Visibility = Visibility.Collapsed;
                    imgWarning.Visibility = Visibility.Visible;
                    imgQuestion.Visibility = Visibility.Collapsed;
                    imgAsterisk.Visibility = Visibility.Collapsed;
                    break;
                case MessageBoxImage.Question:
                    imgError.Visibility = Visibility.Collapsed;
                    imgInfo.Visibility = Visibility.Collapsed;
                    imgWarning.Visibility = Visibility.Collapsed;
                    imgQuestion.Visibility = Visibility.Visible;
                    imgAsterisk.Visibility = Visibility.Collapsed;
                    break;
                case MessageBoxImage.Information:
                    imgError.Visibility = Visibility.Collapsed;
                    imgInfo.Visibility = Visibility.Visible;
                    imgWarning.Visibility = Visibility.Collapsed;
                    imgQuestion.Visibility = Visibility.Collapsed;
                    imgAsterisk.Visibility = Visibility.Collapsed;
                    break;
                case MessageBoxImage.None:
                    imgError.Visibility = Visibility.Collapsed;
                    imgInfo.Visibility = Visibility.Collapsed;
                    imgWarning.Visibility = Visibility.Collapsed;
                    imgQuestion.Visibility = Visibility.Collapsed;
                    imgAsterisk.Visibility = Visibility.Collapsed;
                    break;
            }
        }

        void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            this.Close();
        }

        //private void btnCopyIdTelegram_Click(object sender, RoutedEventArgs e)
        //{
        //    Clipboard.SetText(txtIDTelegram.Text);
        //}

        private void MessageBoxWindow_Unloaded(object sender, RoutedEventArgs e)
        {
            if (!IsDialog)
            {
                Application.Current.MainWindow.IsHitTestVisible = true;
            }
        }
    }
}
